import time
from time import sleep
from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser


class GoodsAttribute(Base):
    # 点击商品管理标签
    def click_goods_management(self):
        self.base_click((By.XPATH, '//div[@id="menu-list"]/ul/li[2]'))

    # 点击添加新商品标签
    def click_add_new_goods(self):
        self.base_click((By.LINK_TEXT, '添加新商品'))


    # 点击商品属性述按钮
    def click_goods_attribute(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, 'main-frame'))
        self.base_click((By.ID, "properties-tab"))

    # 选择商品类型
    def goods_type(self, text):
        self.base_select_value((By.NAME, "goods_type"), text)

    # 选择"书"做示例
    # 填写作者
    def author(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(1) [type='text']"), content)

    # 填写出版社
    def publisher(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(2) [type='text']"), content)

    # 填写图书书号
    def book_id(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(3) [type='text']"), content)

    # 填写出版日期
    def publish_date(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(4) [type='text']"), content)

    # 填写开本
    def format(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(5) [type='text']"), content)

    # 填写图书页数
    def book_page(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(6) [type='text']"), content)

    # 图书装订选择
    def book_bind(self, value):
        self.base_select_value((By.CSS_SELECTOR, "#attrTable tr:nth-child(7) select"), value)

    # 填写图书规格
    def book_spec(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(8) [type='text']"), content)

    # 填写版次
    def book_order(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(9) [type='text']"), content)

    # 填写印张
    def book_sheet(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(10) [type='text']"), content)

    # 填写字数
    def book_words(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(11) [type='text']"), content)

    # 填写所属分类
    def book_classify(self, content):
        self.base_send_keys((By.CSS_SELECTOR, "#attrTable tr:nth-child(12) [type='text']"), content)

    # 点击重置按钮
    def reset(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, "main-frame"))
        self.base_click((By.XPATH, "//div[@class='button-div']/input[3]"))

    # 点击确定按钮
    def sure(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, "main-frame"))
        self.base_click((By.XPATH, "//div[@class='button-div']/input[2]"))


